//
//  UserShareDesCell.m
//  吃货·上海
//
//  Created by 高青松 on 15/11/25.
//  Copyright © 2015年 濮亚军. All rights reserved.
//

#import "UserShareDesCell.h"
#import "UIImageView+WebCache.h"

@interface UserShareDesCell()
@property (nonatomic,strong) UIImageView *iconImageView;// 用户头像
@property (nonatomic,strong) UILabel *userLabel;// 用户名字
@property (nonatomic,strong) UILabel *reviewLabel;// 回复的内容
@property (nonatomic,strong) UIView *lineView;// 横线
@end


@implementation UserShareDesCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        // 用户头像
        CGFloat width = KScreenWidth / 7.5;
        CGFloat height = 50;
        self.iconImageView = [[UIImageView alloc]initWithFrame:CGRectMake(30, 30, height, height)];
//        self.iconImageView.backgroundColor = [UIColor cyanColor];
        self.iconImageView.layer.cornerRadius = height/2;
        self.iconImageView.layer.masksToBounds = YES;
        [self.contentView addSubview:self.iconImageView];
        
        // 用户名字
        self.userLabel = [[UILabel alloc]initWithFrame:CGRectMake(30 + width +10, 30, KScreenWidth - width -30 - 30, 20)];
        self.userLabel.textAlignment = NSTextAlignmentLeft;
        self.userLabel.font = [UIFont systemFontOfSize:15];
//        self.userLabel.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:self.userLabel];
        
        
        // 评论内容
        self.reviewLabel = [[UILabel alloc]initWithFrame:CGRectMake(30 + width + 10, 30 + 20, KScreenWidth - KScreenWidth/7.5 - 30 - 30, 40)];
//        self.reviewLabel.backgroundColor = [UIColor greenColor];
        self.reviewLabel.textAlignment = NSTextAlignmentLeft;
        self.reviewLabel.font = [UIFont systemFontOfSize:17];
        self.reviewLabel.numberOfLines = 0;
        [self.contentView addSubview:self.reviewLabel];
        
//        self.lineView = [[UIView alloc]initWithFrame:CGRectMake(0, self.reviewLabel.frame.size.height + self.reviewLabel.frame.origin.y + 30, KScreenWidth, 1)];
//        self.lineView.backgroundColor = [UIColor grayColor];
//        [self.reviewLabel addSubview:self.lineView];
    }
    return  self;
}

- (void)setModel:(UserShareDesModel *)model
{
    _model = model;
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.imageStr]];
    //self.iconImageView.image = [UIImage imageNamed:model.imageStr];
    self.userLabel.text = model.name;
    self.reviewLabel.text = model.review;
    CGRect reviewBounds = [model.review boundingRectWithSize:CGSizeMake(KScreenWidth - KScreenWidth/7.5, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:17] forKey:NSFontAttributeName] context:nil];
    self.reviewLabel.frame = CGRectMake(30 + KScreenWidth/7.5 + 10, 50 + 20, KScreenWidth-KScreenWidth/7.5, reviewBounds.size.height);
    
    self.lineView = [[UIView alloc]initWithFrame:CGRectMake(0, self.reviewLabel.frame.size.height + self.reviewLabel.frame.origin.y + 30, KScreenWidth, 1)];
    self.lineView.backgroundColor = [UIColor grayColor];
    [self.contentView addSubview:self.lineView];

}



//动态返回cell高度
+(CGFloat)heightForCell:(UserShareDesModel *)model
{
    CGRect reviewBounds = [model.review boundingRectWithSize:CGSizeMake(KScreenWidth - KScreenWidth/7.5, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:17] forKey:NSFontAttributeName] context:nil];
    return 30 + 20 + reviewBounds.size.height + 30 + 30;
}


@end
